package com.oujiong.controller;


import com.google.common.collect.Lists;
import com.oujiong.entity.User;
import com.oujiong.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.PostConstruct;
import java.util.List;


/**
 * @author xub
 * @Description: 接口测试
 * @date 2019/8/24 下午6:31
 */
@RestController
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 模拟插入数据
     */
    List<User> userList = Lists.newArrayList();

    /**
     * 初始化插入数据
     */
    @PostConstruct
    private void getData() {
        userList.add(new User(12L, "小小", "女", 12));
        userList.add(new User(22L, "爸爸", "男", 45));
        userList.add(new User(32L, "妈妈", "女", 55));
        userList.add(new User(42L, "爷爷", "男", 18));
        userList.add(new User(56L, "奶奶", "女", 11));
    }

    /**
     * @Description: 批量保存用户
     */
    @PostMapping("save-user")
    public Object saveUser(@RequestParam("num") Long num, @RequestParam("startId") Long startId) {
        userList.clear();
        for (Long i = 0L; i < num; i++) {
            userList.add(new User(startId + i, "默认数据", "男", 45));
        }
        return userService.insertForeach(userList);
    }

    /**
     * @Description: 获取用户列表
     */
    @GetMapping("list-user")
    public Object listUser() {
        return userService.list();
    }

    @GetMapping("page-user")
    public Object pageUser(@RequestParam("limit") Long limit, @RequestParam("offset") Long offset) {
        return userService.queryForPage(limit, offset);
    }

    @GetMapping("bindTable-user")
    public Object queryForWalltByUserIds(@RequestBody List<Integer> userIds) {
        return userService.queryForWalltByUserIds(userIds);
    }
}
